package base
{
    import base.BaseObject;
    
    import com.dusk.tool.ColorAdjust;
    import com.dusk.tool.DataBase;
    import com.dusk.util.McUtil;
    import com.dusk.util.RandomUtil;
    import com.dusk.util.TextUtil;
    import com.game.ctrler.GadgetQueue;
    import com.game.data.constant.HitType;
    import com.game.data.vo.ActionRecordVO;
    import com.game.data.vo.GameGadgetVO;
    import com.game.data.vo.HitResultVO;
    import com.game.data.vo.HitVO;
    import com.game.engine.phys.Vector2D;
    import com.game.event.GameEventType;
    import com.game.manager.EventManager;
    import com.game.manager.NotificationManager;
    import com.game.manager.SettingManager;
    import com.game.view.ViewerBase;
    import com.game.view.component.GameGadgetType;
    import com.game.view.display.AnimationClip;
    import com.greensock.TweenMax;
    import com.greensock.easing.Cubic;
    
    import export.bullet.EnemyMoveBullet;
    
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.filters.ColorMatrixFilter;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.utils.Dictionary;
    
    public class BaseObject extends ViewerBase
    {
        private static var _id:int = 1;
        
        public function BaseObject()
        {
            super();
            needDestroyWhenRemove = false;
            gameObjectId = BaseObject._id++;
            {
                CONFIG::DEBUG
                {
                    addEventListener(MouseEvent.CLICK, killSelf);
                    buttonMode = true;
                }
            }
        }
        
        public var gameObjectId:uint;
        
        public var collideBox:Rectangle;//碰撞框，相对于自身坐标的一个矩形
        public var collideSprite:Sprite;//在进行复杂碰撞的时候会使用这个sprite进行像素级碰撞
        
        public var isRight:Boolean = false;
        public var isLeft:Boolean = false;
        public var isFly:Boolean = false;
        protected var gravity:Number = 1.5;
        protected var gravityPrev:Number = 1.5;
        
        public var beAttackedTimes:Number = 0;
        
        public var standInObj:BaseTerrain;
        public var headInObj:BaseTerrain;
        public var leftInObj:BaseTerrain;
        public var rightInObj:BaseTerrain;
        
        public var isReadyToDestroy:Boolean = false;
        //当前动作
        public var curAction:String = "idle";
        //动画容器
        public var bodyContainer:Sprite;
        //特效容器
        public var effectContainer:Sprite;
        //速度
        public var velocity:Vector2D;
        public var enforceSpeed:Vector2D;
        public var accelerate:Vector2D;
        public var magicBulletArray:Array;
        public var attackBackInfoDict:Dictionary;
        public var isGXP:Boolean = false;
        public var curAddEffect:BaseAddEffect;
        
        protected var isAlreadyDead:Boolean = false;
        protected var horizonSpeed:int = 5;
        protected var horizonRunSpeed:int = 10;
        protected var jumpPower:int = -20;
        protected var jumpCount:int = 0;
        protected var curMagicWeapon:BaseMagicWeapon;
        protected var bbdc:BaseAnimation = null;
        protected var _framer:int = 0;
        protected var timerDict:DataBase;
        protected var actionRecord:ActionRecordVO;
        
        protected var invincibleCount:int = 0;
        protected var stiffCount:int = 0;
        protected var steelBodyCount:int = 0;
        protected var isTransparent:Boolean;
        
        override protected function beforeAdded():void
        {
            
            velocity = Vector2D.zero;
            accelerate = Vector2D.zero;
            enforceSpeed = Vector2D.zero;
            
            magicBulletArray = [];
            actionRecord = new ActionRecordVO();
            timerDict = new DataBase();
            timerDict.setDefaultValue(int.MIN_VALUE / 2);
            attackBackInfoDict = new Dictionary();
            bodyContainer = new Sprite();
            addChild(bodyContainer);
            effectContainer = new Sprite();
            addChild(effectContainer);
            initCollideArea();
            initBBDC();
        }
        
        override protected function onAdded():void
        {
        }
        
        public function checkCollideTarget(target:BaseObject):Boolean
        {
            return target.getCollideArea().intersects(getCollideArea());
        }
        
        public function checkCollideRect(rect:Rectangle):Boolean
        {
            return rect.intersects(getCollideArea());
        }
        
        public function getCollideArea():Rectangle
        {
            var rect:Rectangle = collideBox.clone();
            rect.offset(x, y);
            return rect;
        }
        
        public function getCollideSprite():Sprite
        {
            if(!collideSprite)
            {
                initCollideArea();
            }
            return collideSprite;
        }
        
        /**
         * 获取下一帧的碰撞区域
         * @return Rectangle
         */
        public function getNextFrameCollideArea():Rectangle
        {
            var rect:Rectangle = getCollideArea();
            rect.offset(velocity.x / (gc.frameClips / 30), velocity.y / (gc.frameClips / 30));
            return rect;
        }
        
        /**
         * 获取相对于舞台的碰撞区域（不是相对于游戏场景）
         * @return Rectangle
         */
        public function getDefiniteCollideArea():Rectangle
        {
            var p:Point = localToGlobal(new Point());
            var rect:Rectangle = collideBox.clone();
            rect.offset(p.x, p.y);
            return rect;
        }
        
        /**
         * 获取碰撞区域的中心点
         * @return
         */
        public function getCollideCenter():Point
        {
            var box:Rectangle = getCollideArea();
            return new Point(box.x + box.width / 2, box.y + box.height / 2);
        }
        
        public function getLocalCollideCenter():Point
        {
            return new Point(collideBox.x + collideBox.width / 2, collideBox.y + collideBox.height / 2);
        }
        
        public function render(ratio:Number = 1):void
        {
            if (!isBeAttacking())
            {
                updateSpeed();
            }
            if (checkCanMove())
            {
                updatePosition(ratio);
            }
            if (curMagicWeapon)
            {
                curMagicWeapon.step();
            }
        }
        
        public function renderAnimate():void
        {
            if (invincibleCount > 0) invincibleCount--;
            if(invincibleCount == 0 && isTransparent)
            {
                isTransparent = false;
            }
            if (stiffCount > 0) stiffCount--;
            if (steelBodyCount > 0) steelBodyCount--;
            if (stiffCount == 0 && curAction == "hurt" && !isDead())
            {
                setAction("idle");
            }
            if (bbdc)
            {
                bbdc.renderAnimate();
            }
            for (var i:int = effectContainer.numChildren - 1; i >= 0; i--)
            {
                var eff:AnimationClip = effectContainer.getChildAt(i) as AnimationClip;
                if (eff)
                {
                    eff.renderAnimate();
                }
            }
            if (curAddEffect)
            {
                curAddEffect.step();
            }
            if (curMagicWeapon)
            {
                curMagicWeapon.step();
            }
            checkOver();
            _framer++;
        }
        
        public function step():void
        {
        }
        
        public function addCurAddEffect(param1:Array):void
        {
            if (curAddEffect)
            {
                curAddEffect.addEffects(param1);
            }
        }
        
        public function hit(bul:BaseBullet, target:BaseObject,result:HitResultVO):void
        {
        
        }
        
        /**
         * 被子弹碰撞
         * @param bul 子弹
         * @param target 子弹主人
         * @return {
         *     "success":true,
         *     "hurt":0,
         *     "isCrit":false,
         *     "isMiss":false
         * }
         */
        public function beHit(bul:BaseBullet, target:BaseObject):HitResultVO
        {
            return new HitResultVO();
        }
        
        /**
         * 检查是否有当前效果
         * @param type 效果
         * @return 是否有此效果
         */
        public function hasAddEffect(type:int):Boolean
        {
            if (!curAddEffect)
            {
                return false;
            }
            return curAddEffect.hasEffect(type);
        }
        
        public function isCanMoveWhenAttack():Boolean
        {
            return false;
        }
        
        public function stopMoveL():void
        {
            isLeft = false;
            
            if (isRight)
            {
                bbdc.turnRight();
            }
            else
            {
                if (!isAttacking() && !isInSky() && !isIdle())
                {
                    setAction("idle");
                }
                if (!isCanMoveWhenAttack())
                {
                    velocity.x = 0;
                }
            }
        }
        
        public function stopMoveR():void
        {
            isRight = false;
            
            if (isLeft)
            {
                bbdc.turnLeft();
            }
            else
            {
                if (!isAttacking() && !isInSky() && !isIdle())
                {
                    setAction("idle");
                }
                if (!isCanMoveWhenAttack())
                {
                    velocity.x = 0;
                }
            }
        }
        
        public function setAttackBack(pos:Point):void
        {
            if (pos.x < 0)
            {
//                isLeft = true;
//                isRight = false;
                if (curAction != "hurt")
                {
                    turnRight();
                }
                if (getDefiniteCollideArea().left < 0)
                {
                    velocity.x = 0;
                    velocity.y = pos.y;
                    return;
                }
            }
            else
            {
//                isLeft = false;
//                isRight = true;
                if (curAction != "hurt")
                {
                    turnLeft();
                }
                if (getDefiniteCollideArea().right > 940)
                {
                    velocity.x = 0;
                    velocity.y = pos.y;
                    return;
                }
            }
            velocity.x = pos.x;
            velocity.y = pos.y;
            TweenMax.to(velocity, 0.6, {"x": velocity.x * 0.2, "ease": Cubic.easeOut});
        }
        
        public function beMagicAttack(param1:BaseBullet, param2:BaseObject, param3:Boolean = false):Boolean
        {
            return false;
        }
        
        /**
         * 判断当前的物体运动时是否会超出屏幕范围
         * @return 是否超出
         */
        public function isInScreen():Boolean
        {
            var rect:Rectangle = getDefiniteCollideArea();
            rect.offset(velocity.x, velocity.y);
            return (rect.left > 10 && rect.right < 920) || (rect.left <= 10 && velocity.x > 0) || (rect.right >= 920 && velocity.x < 0);
        }
        
        /**
         * 释放法宝
         */
        public function releaseMagicWeapon():void
        {
            curMagicWeapon = null;
        }
        
        /**
         * 函数废弃
         * 获取真实伤害
         * @param param1
         * @param param2
         * @return
         */
        public function getRealPower(param1:String, param2:Boolean = true):int
        {
            return 0;
        }
        
        public function getActionHurt(action:String):int
        {
            return getAtk() * RandomUtil.randNum(0.9,1.1);
        }
        
        public function setAction(action:String):void
        {
            curAction = action;
            if (action != "idle" && action != "idle2")
            {
                actionRecord.addAction(action);
            }
            if (action == "dead")
            {
                bbdc.play();
            }
        }
        
        public function isNormalHit():Boolean
        {
            return true;
        }
        
        public function isJump():Boolean
        {
            return curAction == "jump1" || curAction == "jump2" || curAction == "jump3";
        }
        
        public function isInSky():Boolean
        {
            return !standInObj;
        }
        
        public function isWalkOrRun():Boolean
        {
            return true;
        }
        
        public function isAttacking():Boolean
        {
            return curAction.indexOf("attack") + curAction.indexOf("skill") != -2;
        }
        
        public function isBeAttacking():Boolean
        {
            return curAction == "hurt" || curAction == "afterHurt" || curAction == "dead";
        }
        
        public function isIdle():Boolean
        {
            return curAction == "idle";
        }
        
        public function isStatic():Boolean
        {
            return !isLeft && !isRight;
        }
        
        public function isDead():Boolean
        {
            return isAlreadyDead;
        }
        
        /**
         * 减少血量且会显示伤害数值
         * @param vo 伤害在vo中定义
         * @param atkObject 攻击者，如果不传入此参数，则不会计算破魔值，直接按照魔抗值减伤害
         */
        public function loseHp(vo:HitResultVO,atkObject:BaseObject = null):void
        {
            var hitVO:HitVO = new HitVO();
            hitVO.hitType = vo.hitType;
            vo.hurt = calculateHurt(vo.hurt, hitVO, atkObject);
            addHurtNumber(vo);
            reduceHp(vo.hurt);
        }
        
        /**
         * 减少血量，此API会直接修改血量并且不会显示伤害值。所有的值都不会经过计算
         * 若要显示伤害值，请使用loseHp方法
         * @param value 伤害值
         */
        public function reduceHp(value:int = 0):void
        {
        }
        
        public function calculateHurt(hurt:int, vo:HitVO, target:BaseObject = null):int
        {
            switch (vo.hitType)
            {
                case HitType.PHYSICS:
                    hurt -= getDef();
                    break;
                case HitType.MAGIC:
                    var def:int = getMagicDef() - (target ? target.getDeMagicDef() : 0);
                    if (def < 0) def = 0;
                    if (def > 1) def = 1;
                    hurt *= 1 - 0.01 * def;
                    break;
                case HitType.REAL:
                default:
                    hurt *= 1;
            }
            return hurt <= 0 ? 1 : hurt;
        }
        
        public function addHurtNumber(vo:HitResultVO):void
        {
            var gadget:GameGadgetVO = new GameGadgetVO();
            gadget.position = new Point(x,getCollideArea().top);
            if(vo.isMiss)
            {
                gadget.type = GameGadgetType.MISS;
            }
            if(vo.isBingo)
            {
                gadget.type = GameGadgetType.BINGO;
            }
            EventManager.getIns().dispatchEvent(GameEventType.ADD_GAME_GADGET, gadget);
        }
        
        /**
         * 停止移动
         */
        public function setStatic():void
        {
            isLeft = false;
            isRight = false;
            velocity.x = 0;
        }
        
        public function isInvincible():Boolean
        {
            return invincibleCount > 0;
        }
        
        public function isStiff():Boolean
        {
            return stiffCount > 0;
        }
        
        public function isSteelBody():Boolean
        {
            return steelBodyCount > 0;
        }
        
        public function setInvincible(frame:int,isTrans:Boolean = false):void
        {
            invincibleCount = frame;
            isTransparent = isTrans;
        }
        
        public function setStiff(frame:int):void
        {
            stiffCount = frame;
            if (stiffCount > 0)
            {
                setAction("hurt");
            }
        }
        
        public function setSteelBody(frame:int):void
        {
            steelBodyCount = frame;
        }
        
        /**
         * 设置失重
         */
        public function setLostGravity():void
        {
            gravity = 0;
        }
        
        public function getBBDC():BaseAnimation
        {
            return bbdc;
        }
        
        /**
         * 恢复重力
         */
        public function resetGravity():void
        {
            if (!isGXP)
            {
                gravity = 1.5;
            }
            else
            {
                gravity = 3.75;
            }
        }
        
        /**
         * 改变物体颜色，在不同难度等级的怪物上使用
         * @param hue 色彩偏移
         */
        public function setHue(hue:int):void
        {
            if (bbdc)
            {
                var cAdjust:ColorAdjust = new ColorAdjust();
                cAdjust.adjustHue(hue);
                var cFilter:ColorMatrixFilter = new ColorMatrixFilter([cAdjust]);
                bbdc.filters = [cFilter];
            }
        }
        
        public function iswor():*
        {
            if (!isRunning())
            {
                setAction("walk");
            }
            else
            {
                setAction("run");
            }
        }
        
        public function getHpMax():int
        {
            return 0;
        }
        
        public function getMpMax():int
        {
            return 0;
        }
        
        public function getHp():int
        {
            return 0;
        }
        
        public function getMp():int
        {
            return 0;
        }
        
        public function getAtk():int
        {
            return 0;
        }
        
        public function getDef():int
        {
            return 0;
        }
        
        public function getCrit():int
        {
            return 0;
        }
        
        public function getToughness():int
        {
            return 0;
        }
        
        public function getHit():int
        {
            return 0;
        }
        
        public function getMiss():int
        {
            return 0;
        }
        
        public function getCritDamage():int
        {
            return 0;
        }
        
        public function getDeCritDamage():int
        {
            return 0;
        }
        
        public function getMagicDef():int
        {
            return 0;
        }
        
        public function getDeMagicDef():int
        {
            return 0;
        }
        
        public function cureHp(value:int = 0):void
        {
            if(value > 0)
            {
                var vo:GameGadgetVO = new GameGadgetVO(GameGadgetType.NUM_HERO_CURE_HP, new Point(x, getCollideArea().top));
                vo.value = value;
                EventManager.getIns().dispatchEvent(GameEventType.ADD_GAME_GADGET, vo);
            }
        }
        
        public function cureMp(value:int = 0):void
        {
            if(value > 0)
            {
                var vo:GameGadgetVO = new GameGadgetVO(GameGadgetType.NUM_HERO_CURE_MP, new Point(x, getCollideArea().top));
                vo.value = value;
                EventManager.getIns().dispatchEvent(GameEventType.ADD_GAME_GADGET, vo);
            }
        }
        
        protected function initCollideArea():void
        {
            if(collideBox)
            {
                collideSprite = new Sprite();
                collideSprite.visible = false;
                collideSprite.cacheAsBitmap = true;
                collideSprite.x = collideSprite.y = 0;
                collideSprite.graphics.beginFill(0xFF0000,0.4);
                collideSprite.graphics.drawRect(collideBox.x,collideBox.y,collideBox.width,collideBox.height);
                collideSprite.graphics.endFill();
                addChildAt(collideSprite,0);
            }
            CONFIG::DEBUG{
                if(gc.debugParam.displayBeAttackRegion)
                {
                    graphics.beginFill(0x0000FF);
                    graphics.drawCircle(0, 0, 5);
                    graphics.endFill();
                    if(collideSprite)
                    {
                        collideSprite.visible = true;
                    }
                }
            }
        }
        
        protected function initBBDC():void
        {
        }
        
        protected function onEnterFrame(action:String, frameCount:int):void
        {
        }
        
        protected function onActionOver(action:String):void
        {
        }
        
        protected function checkOver():void
        {
        }
        
        /**
         * 无双状态开启
         */
        protected function turnToGXP():void
        {
        }
        
        public function moveTo(mx:int, my:int):void
        {
            var col:Rectangle = getCollideArea().clone();
            col.offset(mx, my);
            var canMove:Boolean = true;
            for each(var wall:BaseTerrain in gc.pWorld.getTerrainArray())
            {
                if (wall === standInObj)
                {
                    continue;
                }
                if (wall.checkCollideRect(col))
                {
                    canMove = false;
                    break;
                }
            }
            if (canMove)
            {
                x += mx;
                y += my;
            }
        }
        
        protected function updateSpeed():void
        {
            if (isCannotMoveWhenAttack())
            {
                velocity.x = 0;
                velocity.y = 0;
                return;
            }
            if (isCannotMoveWhenAttackOnFloor() && !isInSky())
            {
                velocity.x = 0;
                return;
            }
            if (!isCanMoveWhenAttack())
            {
                var currentSpeed:Number = isRunning() ? horizonRunSpeed : horizonSpeed;
                if (isLeft)
                {
                    velocity.x = -currentSpeed;
                }
                else if (isRight)
                {
                    velocity.x = currentSpeed;
                }
            }
        }
        
        protected function isRunning():Boolean
        {
            return false;
        }
        
        protected function checkCanMove():Boolean
        {
            if (isFly)
            {
                return isInScreen();
            }
            standInObj = null;
            headInObj = null;
            leftInObj = null;
            rightInObj = null;
            for each (var wall:BaseTerrain in gc.pWorld.getTerrainArray())
            {
                var area:Rectangle;
                if (wall is BaseTerrain)
                {
                    area = (wall as BaseTerrain).getNextFrameCollideArea();
                }
                else
                {
                    area = wall.getBounds(gc.gameScene);
                }
                if (area.intersects(getNextFrameCollideArea()))
                {
                    nearToWall(wall);
                    /*if ((wall.rotation != 0 && Math.round(wall.rotation) != 90 && !wall.isOutOfThisLine(this)) || wall.rotation != 0 && Math.round(wall.rotation) != 90 && wall.isOutOfThisLine(this)/!* && Boolean(area.intersects(getNextFrameXBounds()))*!/)
                    {
                        //这条逻辑直接不走，时判断那种斜坡的，可以保留
                        //前期地图主要还是以水平和竖直框架为主
                        if (!selfBitmap)
                        {
                            var bmd:BitmapData = new BitmapData(colipse.width, colipse.height, true, 0x222222)
                            bmd.draw(colipse, new Matrix(1, 0, 0, 1, colipse.width / 2, colipse.height / 2));
                            selfBitmap = new Bitmap(bmd);
                            selfBitmap.x = x - Number(selfBitmap.width) / 2 + speed.x;
                            selfBitmap.y = y - Number(selfBitmap.height) / 2 + speed.y;
                        }
                        else
                        {
                            selfBitmap.x = x - Number(selfBitmap.width) / 2 + speed.x;
                            selfBitmap.y = y - Number(selfBitmap.height) / 2 + speed.y;
                        }
                        var matrix:Matrix = wall.transform.matrix;
                        matrix.tx = Number(wall.width) / 2;
                        matrix.ty = Number(wall.height) / 2;
                        if (!wallBitmap)
                        {
                            var bdm2:BitmapData = new BitmapData(wall.width, wall.height, true, 2236962);
                            //不知道有什么用，赋值了但从未读取
                            // var _loc6_:Number = Number(wall.rotation) * Math.PI / 180;
                            bdm2.draw(wall, matrix);
                            wallBitmap = new Bitmap(bdm2);
                            wallBitmap.name = wall.name;
                            wallBitmap.x = Number(wall.x) - Number(wallBitmap.width) / 2;
                            wallBitmap.y = Number(wall.y) - Number(wallBitmap.height) / 2;
                        }
                        else if (wallBitmap.name != wall.name)
                        {
                            wallBitmap.bitmapData.fillRect(wallBitmap.bitmapData.rect, 16777215);
                            wallBitmap.bitmapData.draw(wall, matrix);
                            wallBitmap.x = Number(wall.x) - Number(wallBitmap.width) / 2;
                            wallBitmap.y = Number(wall.y) - Number(wallBitmap.height) / 2;
                            wallBitmap.name = wall.name;
                        }
                        else
                        {
                            wallBitmap.x = Number(wall.x) - Number(wallBitmap.width) / 2;
                            wallBitmap.y = Number(wall.y) - Number(wallBitmap.height) / 2;
                        }
                        if (selfBitmap.bitmapData.hitTest(new Point(selfBitmap.x, selfBitmap.y), 0, wallBitmap.bitmapData, new Point(wallBitmap.x, wallBitmap.y), 1))
                        {
                            _loc7_ = wall.setYByRole(this);
                            if (!isLeft && !isRight && !isAttacking() && !isBeAttacking())
                            {
                                if (!isWaiting())
                                {
                                    setAction("idle");
                                }
                            }
                            if (speed.y > 0)
                            {
                                getDownFloor();
                            }
                            speed.x = _loc7_.x;
                            speed.y = _loc7_.y;
                        }
                    }
                    else
                    {
                        if (selfBitmap)
                        {
                            selfBitmap.bitmapData.dispose();
                            selfBitmap = null;
                        }
                        if (wallBitmap)
                        {
                            wallBitmap.bitmapData.dispose();
                            wallBitmap = null;
                        }
                    }*/
                }
            }
            if (!isInScreen())
            {
                velocity.x = 0;
            }
            return true;
        }
        
        protected function nearToWall(wall:BaseTerrain):void
        {
            var barrierArea:Rectangle = wall.getCollideArea();
            var selfBound:Rectangle = getCollideArea();
            var nextFramePosY:Number = 8 + Math.max(Math.abs(velocity.y), Math.abs(wall.velocity.y));
            var nextFramePosX:Number = 8 + Math.max(Math.abs(velocity.x), Math.abs(wall.velocity.x));
            if (velocity.y > 0 && selfBound.bottom <= barrierArea.top + nextFramePosY)
            {
                if (selfBound.right > barrierArea.left && selfBound.left < barrierArea.right)
                {
                    standInObj = wall;
                    y = barrierArea.top - 0.1;
                    velocity.y = 0;
                    getDownFloor();
                }
//				if (!wall.getChildByName("isThroughDownButUpWall"))
//				{
//					if (wall is ThroughWall)
//					{
//						standInObj = wall;
//						y = Number(barrierArea.y) - 0.1 - colipse.height / 2;
//						speed.y = 0;
//						getDownFloor();
//					}
//					else if (selfBound.x + selfBound.width > barrierArea.x && selfBound.x < barrierArea.x + barrierArea.width)
//					{
//						standInObj = wall;
//						y = Number(barrierArea.y) - 0.1;
//						speed.y = 0;
//						getDownFloor();
//					}
//				}
            }
            if (velocity.x <= 0 && selfBound.left >= barrierArea.right - nextFramePosX && selfBound.bottom >= barrierArea.top && selfBound.top <= barrierArea.bottom)
            {
                leftInObj = wall;
                velocity.x = 0;
            }
            if (velocity.x >= 0 && selfBound.right <= barrierArea.left + nextFramePosX && selfBound.bottom >= barrierArea.top && selfBound.top <= barrierArea.bottom)
            {
                rightInObj = wall;
                velocity.x = 0;
            }
//			if (!(Boolean(wall.getChildByName("isThroughWall")) || Boolean(wall.getChildByName("isThroughUpButDownWall"))))
//			{
//				if (speed.y <= 0 && selfBound.y > barrierArea.y + objectArea.height)
//				{
//					headInObj = wall;
//					y = barrierArea.y + barrierArea.height + 0.1 + colipse.height / 2;
//					speed.y = 0;
//				}
//				if (speed.x <= 0 && (selfBound.x >= objectArea.x + objectArea.width && selfNextBound.x <= barrierArea.x + barrierArea.width && selfNextBound.x + selfNextBound.width >= barrierArea.x) && getBottom() > barrierArea.y + 5)
//				{
//					leftInObj = wall;
//					x = barrierArea.x + barrierArea.width + 2 + colipse.width / 2;
//					speed.x = 0;
//				}
//				if (speed.x >= 0 && (selfBound.x <= objectArea.x && selfNextBound.x + selfNextBound.width >= barrierArea.x && selfNextBound.x <= barrierArea.x + barrierArea.width) && getBottom() > barrierArea.y + 5)
//				{
//					rightInObj = wall;
//					x = Number(barrierArea.x) - 2 - colipse.width / 2;
//					speed.x = 0;
//				}
//			}
        }
        
        protected function move():void
        {
        }
        
        protected function updatePosition(ratio:Number = 1):void
        {
            x += velocity.x / ratio;
            y += velocity.y / ratio;
            velocity.y += gravity / ratio;
            velocity.x += accelerate.x / ratio;
            velocity.y += accelerate.y / ratio;
            x += enforceSpeed.x / ratio;
            y += enforceSpeed.y / ratio;
        }
        
        protected function moveLeft():void
        {
            if (!isAttacking())
            {
                turnLeft();
                if (!isInSky() && !isAttacking() && !isBeAttacking())
                {
                    iswor();
                }
            }
        }
        
        
        public function getSpeedValue():Number
        {
            return Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
        }
        
        public function setSpeed(x:Number = 0, y:Number = 0):void
        {
            velocity.setXY(x, y);
        }
        
        public function setSpeedAdd(x:Number = 0, y:Number = 0):void
        {
            accelerate.setXY(x, y);
        }
        
        public function turnLeft():void
        {
            isLeft = true;
            isRight = false;
            bbdc.turnLeft();
        }
        
        protected function moveRight():void
        {
            if (!isAttacking())
            {
                turnRight();
                if (!isInSky() && !isAttacking() && !isBeAttacking())
                {
                    iswor();
                }
            }
        }
        
        public function turnRight():void
        {
            isRight = true;
            isLeft = false;
            bbdc.turnRight();
        }
        
        protected function stopMove():void
        {
            if (isLeft)
            {
                stopMoveL();
            }
            else if (isRight)
            {
                stopMoveR();
            }
            if (!isIdle())
            {
                setAction("idle");
            }
        }
        
        protected function addBeAttackEffect():void
        {
            //被打时添加特效，在子类中实现
        }
        
        protected function shadowEffect():void
        {
            if(!SettingManager.getSettingVO().isShowShadowEffect)
            {
                return;
            }
            McUtil.shallowEffect(this);
        }
        
        protected function getAttackBackSpeed(bullet:BaseBullet, vo:HitVO):Point
        {
            if (!vo)
            {
                return new Point(0, 0);
            }
            var _p:Point = vo.attackBack.clone();
            if (bullet is EnemyMoveBullet)
            {
                if (bullet.velocity.x < 0)
                {
                    _p.x = -Math.abs(_p.x);
                }
                else
                {
                    _p.x = Math.abs(_p.x);
                }
            }
            else
            {
                _p.x *= bullet.getDirect();
            }
            if (vo.isTraction)
            {
                _p.x = x < bullet.getOwner().x ? Math.abs(_p.x) : -Math.abs(_p.x);
                _p.y = y < bullet.getOwner().y ? Math.abs(_p.y) : -Math.abs(_p.y);
            }
            return _p;
            /*else if (bullet is SpecialEffectBullet || bullet is FollowTargetBullet || bullet is VirtualBullet)
            {
                if (bullet.getBulletName() == "Role2Bullet3" || bullet.getBulletName() == "Role1Bullet10_4")
                {
                    if (x > bullet.owner.x)
                    {
                        _p.x = Math.abs(_p.x);
                    }
                    else
                    {
                        _p.x = -Math.abs(_p.x);
                    }
                }
                else if (bullet.getBulletName() == "Role1Bullet10_2" || bullet.getBulletName() == "Role4BulletArrow12_2")
                {
                    if (x > bullet.owner.x)
                    {
                        _p.x = -Math.abs(_p.x);
                    }
                    else
                    {
                        _p.x = Math.abs(_p.x);
                    }
                }
                else if (bullet.getDirect() == -1)
                {
                    _p.x = -Math.abs(_p.x);
                }
                else
                {
                    _p.x = Math.abs(_p.x);
                }
            }
            return _p;*/
        }
        
        protected function jump():void
        {
            velocity.y = jumpPower;
        }
        
        protected function getDownFloor():void
        {
            if (!isAttacking() && !isBeAttacking())
            {
                if (isLeft || isRight)
                {
                    iswor();
                }
                else if (!isIdle())
                {
                    setAction("idle");
                }
            }
            jumpCount = 0;
        }
        
        protected function getDownStair():void
        {
            if (Boolean(standInObj) && Boolean(standInObj.getChildByName("isThroughWall")))
            {
                y += 20;
                setAction("jump1");
                jumpCount = 2;
            }
        }
        
        protected function isCannotMoveWhenAttackOnFloor():Boolean
        {
            return false;
        }
        
        protected function isCannotMoveWhenAttack():Boolean
        {
            return false;
        }
        
        public function destroy():void
        {
        }
        
        CONFIG::DEBUG
        {
            private function killSelf(param1:MouseEvent):void
            {
                reduceHp(1000000);
            }
        }
    }
}
